package homework;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Homework_P1M3_4_Main {
    public static void getStart() {
      	// 定一个存放学生对象的list
        List<Homework_P1M3_4_Student> listStudents = new LinkedList<>();
      	// 获取输入
        Scanner sc = new Scanner(System.in);
      	// 用于接收输入的值
        int age;
        int id;
        String name;

        while (true) {
          	// 打印菜单
            System.out.println("1、增加学生信息；\n" + "2、查询学生信息；\n" + "3、删除学生信息；\n" + "4、修改学生信息；\n" + "5、打印所有学生；\n" + "0、退出；");
          	// 获取输入的菜单选项
            int flag = sc.nextInt();
            switch (flag) {
                // 增加
                case 1:
                    System.out.println("输入id");
                    id = sc.nextInt();
                    System.out.println("输入姓名");
                    name = sc.next();
                    System.out.println("输入年龄");
                    age = sc.nextInt();
                    Homework_P1M3_4_AddStudent.AddStudent(id, name, age, listStudents);
                    break;
                // 查找
                case 2:
                    System.out.println("输入id");
                    id = sc.nextInt();
                    Homework_P1M3_4_Student seachStudent = Homework_P1M3_4_SearchStudent.seachStudent(id, listStudents);
                    if (null == seachStudent) {
                        System.out.println("无对象");

                    } else {
                        System.out.println("搜索成功" + seachStudent);
                    }

                    break;

                case 3:
                    System.out.println("输入需要删除的id");
                    id = sc.nextInt();
                    Homework_P1M3_4_DeleteStudent.Homework_P1M3_4_DeleteStudent(id, listStudents);

                    break;
								// 修改-->先查询、再修改
                case 4:
                    System.out.println("输入要修改的id");
                    id = sc.nextInt();
                    Homework_P1M3_4_Student getStudent = Homework_P1M3_4_SearchStudent.seachStudent(id, listStudents);
                		// 如果查询结果为null，则退出，否则执行下面的修改操作
                    if (null == getStudent) {
                        System.out.println("无对象");
                        break;
                    }
                    System.out.println("输入id");
                    id = sc.nextInt();
                    System.out.println("输入姓名");
                    name = sc.next();
                    System.out.println("输入年龄");
                    age = sc.nextInt();
                    Homework_P1M3_4_ChangeStudent.Homework_P1M3_4_ChangeStudent(id, name, age, getStudent);

                    break;
								// 打印所有对象
                case 5:
                    System.out.println("print");
                    Homework_P1M3_4_PrintStudent.Homework_P1M3_4_PrintStudent(listStudents);

                    break;
                // 打印退出系统
                case 0:
                    System.out.println("正在退出系统...");
                    break;

                default:
                    System.out.println("请重新选择");
                    break;
            }
           // 结束循环，退出系统
            if (0 == flag)
                break;

        }

        sc.close();

    }
}

